import {Http} from '@angular/http';
import {NgLayer, NgLayerRef} from 'ng2-layer';
import {Component,ViewContainerRef, Injectable}  from '@angular/core';
import {ActivatedRoute} from '@angular/router';
/**
 * 左侧菜单部分
 */
@Component({
	selector: '.box_ship',
	templateUrl: 'template/router/boxSetting/ship.html'
})
export class BoxShipComp {
	shipConfig:any = {
		"underlineOrder": {
			"is_open": false,
			"after_time": 0,
			"interval_time": 0
		},
		"startingFare": {
			"cost": 0
		},
		"shipFee": {
			"cost": 0,
			"all_order": "0",
			"full_cost": 0
		}
	};
	
	constructor(private http:Http, router:ActivatedRoute){
		router.parent.params.subscribe(params => {
			this.boxId = params.id;
			http.get({
				search:{
					m:"Admin",
					c:"ApiBox",
					a:"getDistribution",
					box_id:this.boxId
				}
			}).then((data)=>{
				this.shipConfig = data.data;
			})
		});
	}
	
	/*
	 * 保存催单设置
	 */
	saveUnderLine(){
		let udLine = this.shipConfig.underlineOrder;
		this.http.post({
			search:{
				m:"Admin",
				c:"ApiBox",
				a:"setDistribution"
			},
			body:{
				box_id:this.boxId,
				action:"underlineOrder",
				json_info:JSON.stringify({
					is_open: udLine.is_open?1:0,
					after_time: udLine.after_time,
					interval_time: udLine.interval_time
				})
			}
		}).then((data)=>{
			
		})
	}
	
	/**
	 * 保存起送价
	 */
	saveStartingFare(){
		let fare = this.shipConfig.startingFare;
		this.http.post({
			search:{
				m:"Admin",
				c:"ApiBox",
				a:"setDistribution"
			},
			body:{
				box_id:this.boxId,
				action:"startingFare",
				json_info:JSON.stringify({
					cost:fare.cost
				})
			}
		}).then((data)=>{
			
		})
	}
	
	/**
	 * 保存配送费用
	 */
	saveShipFee(){
		let shipFee = this.shipConfig.shipFee;
		this.http.post({
			search:{
				m:"Admin",
				c:"ApiBox",
				a:"setDistribution"
			},
			body:{
				box_id:this.param.id,
				action:"shipFee",
				json_info:JSON.stringify({
					cost:shipFee.cost,
					all_order: shipFee.all_order?1:0,
					full_cost:shipFee.full_cost
				})
			}
		}).then((data)=>{
			
		})
	}
}